package br.org.bertol.mestrado;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public enum InputType {
	DEPEDENCIA{
		private List<List<Integer>> matrix = new ArrayList<List<Integer>>();
		
		@Override
		List<List<Integer>> loadWeekConstraint(String source, String system)
				throws IOException {
			
			matrix = readInput(source, system, "_depe.txt");
			
			return matrix;
		}

		@Override
		int getWeekConstraintHeight(int classe, int constraint) {
			return 1;
		}
	},
	METODO{
		
		private List<List<Integer>> matrix = new ArrayList<List<Integer>>();
		
		@Override
		List<List<Integer>> loadWeekConstraint(String source, String system)
				throws IOException {
			matrix = readInput(source, system, "_meth.txt");
			
			return matrix;
		}

		@Override
		int getWeekConstraintHeight(int classe, int constraint) {
			return constraint;
		}
	},
	ATRIBUTO{
		
		private List<List<Integer>> matrix = new ArrayList<List<Integer>>();
		
		@Override
		List<List<Integer>> loadWeekConstraint(String source, String system)
				throws IOException {
			
			matrix = readInput(source, system, "_attr.txt");
			
			return matrix;
		}

		@Override
		int getWeekConstraintHeight(int classe, int constraint) {
			return constraint;
		}
	};
	
	abstract List<List<Integer>> loadWeekConstraint(final String source, final String system) throws IOException;
	
	abstract int getWeekConstraintHeight(final int classe, int constraint);
	
	List<List<Integer>> loadStrongConstraint(final String source, final String system) throws IOException
	{
		return readInput(source, system, "_prece.txt");
	}
	
	
	protected List<List<Integer>> readInput(final String source, final String system, final String typeInput) throws IOException
	{
		final List<List<Integer>> colluns = new ArrayList<List<Integer>>();
		
		final File inputFile = new File(source+"/"+system+typeInput);
		
		if(!inputFile.exists())
			return colluns;
		
		final Scanner reader = new Scanner(inputFile);
		
		// caminha pela matriz de entrada
		while (reader.hasNext())
		{
			String []input = reader.nextLine().split(" ");
			
			List<Integer> row = new ArrayList<Integer>();
			
			// adiciona as classes a uma lista
			for (String c : input)
				row.add(Integer.parseInt(c));
			
			colluns.add(row);
		}
		
		return colluns;
	}
}
